package com.xander.myblog.service.impl;

import com.xander.myblog.constant.Constants;
import com.xander.myblog.entity.Topic;
import com.xander.myblog.mapper.TopicMapper;
import com.xander.myblog.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 * @author hbxz
 * @date 2018-12-19
 */
@Service
public class TopicServiceImpl implements TopicService {
    @Autowired
    private TopicMapper topicMapper;

    @Override
    public List<Topic> getDeletedTopic() {
        return topicMapper.getTopicByDelFlag(0);
    }

    @Override
    public List<Topic> getExistTopic() {
        return topicMapper.getTopicByDelFlag(1);
    }

    @Override
    public List<Topic> getAllTopic() {
        return topicMapper.getAllTopic();
    }

    @Override
    public void insertTopic(Topic topic) {
        topic.setCreateTime(new Date());
        topicMapper.insertTopic(topic);
    }

    @Override
    public void updateTopic(Topic topic) {
        topic.setUpdateTime(new Date());
        topicMapper.updateTopic(topic);
    }

    @Override
    public Topic getTopicByTid(Long tid) {
        return topicMapper.getTopicByTid(tid);
    }

    @Override
    public void deleteTopic(Topic topic) {
        topic.setUpdateTime(new Date());
        topic.setDelFlag(Constants.IS_DELETED);
        topicMapper.updateTopic(topic);
    }
}
